using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WPCoco.DataStrucure
{
    /// <summary>
    /// Set data structure
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Set<T> : ICollection<T>
    {
        Dictionary<T, object> dict = new Dictionary<T, object>();

        #region ICollection<T> Members

        public void Add(T item)
        {
            dict[item] = null;
        }

        public void Clear()
        {
            dict.Clear();
        }

        public bool Contains(T item)
        {
            if (item == null) return false;
            return dict.ContainsKey(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            dict.Keys.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return dict.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(T item)
        {
            return dict.Remove(item);
        }

        #endregion

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return dict.Keys.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }
}
